package route

import (
	"net/http"

	"github.com/gorilla/mux"
	"main/comm"
)

type Route struct {
	Name        string
	Method      string
	Pattern     string
	BasicAuth   bool
	HandlerFunc http.HandlerFunc
}

type Routes []Route

type RoutesArr []Routes

var routesArr = RoutesArr{routes_unver, routes_v1}

func NewRouter() *mux.Router {
	router := mux.NewRouter().StrictSlash(true)

	for _, routes := range routesArr {
		for _, route := range routes {
			var handler http.Handler
			handler = route.HandlerFunc
			if route.BasicAuth {
				handler = comm.BasicAuth(handler)
			}
			handler = comm.Logger(handler, route.Name)

			router.
				Methods(route.Method).
				Path(route.Pattern).
				Name(route.Name).
				Handler(handler)
		}
	}
	return router
}
